var query = function(){
	asyncSubmit("produceManagerDetailForm");
};

/*========================================明细操作==============================================*/
var toEditProduceDetail = function(proDetailId,proPlanItemName,unit){
	//添加明细弹窗
	$.box('.onlyuserforaddtaskalertbox', {
		onOpen : function() {
			$("#proDetailId").val(proDetailId);
			$("#proPlanItemName").html(proPlanItemName);
			$("#unit").val(unit);
			$('#scrollbar').tinyscrollbar();
			$('#scrollbar_002').tinyscrollbar();//里面有2个滚动条*/		
		}
	}, {
		submit:{
			close:false,
			dom:['#saveProduceDetail'],
			fun:function(index){
				var currObj = this;
				saveProduceDetail(function(){					
					currObj.close(index);
				});
				
			}
		},
		close : {
			dom : [ '.onlyuserforaddtaskalertbox .closeforaddtask','.onlyuserforaddtaskalertbox .c_but_no' ]
		}
	});
	
};

//添加明细
var saveProduceDetail = function(callback){
	
	if(validate()){		
		var fun = function(msg) {
			if (msg.result == "success") {
				if(callback){
					callback();
				}
				layer.msg("保存明细成功！",1,9,function(){
					query();
				});
			} else {
				layer.alert(msg.result);
			};
		};
		
		ajaxCommFunWithDataType(globePath+"/produce/savePProduceDetail.htm", $("#editProduceDetailForm").serialize(),'json',fun);
	}
};
//验证
var validate = function(){
	var realStartDate = $.trim($("#realStartDate").val());
	if(realStartDate==''){
		layer.msg("实际开始时间不能为空");
		return false;
	}
	var realEndDate = $.trim($("#realEndDate").val());
	if(realEndDate==''){
		layer.msg("实际结束时间不能为空");
		return false;
	}
	var count = $.trim($("#count").val());
	if(count==''){
		layer.msg("数量不能为空");
		return false;
	}
	var unit = $.trim($("#unit").val());
	if(unit==''){
		layer.msg("单位不能为空");
		return false;
	}
	return true;
};
